<template>
	<view class="page">
		<view class="list" v-if="comit">
			<view class="item">
				<text class="key">审批人选择</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<picker :value="approvalIndex" :range="approvalArrayName" @change="approvalChange">{{approvalArrayName[approvalIndex]==undefined?"请选择":approvalArrayName[approvalIndex]}}
				</picker>
			</view>
			<view class="item" @tap="editName">
				<text class="key">姓名</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<text class="value">{{name}}</text>
			</view>
			<uni-popup ref="popupName" type="dialog">
				<uni-popup-dialog mode="input" title="姓名" :value="name" placeholder="请填写真实姓名" @confirm="finishName">
				</uni-popup-dialog>
			</uni-popup>
			<view class="item">
				<text class="key">生日</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<picker :value="birthday" mode="date" @change="birthdayChange">
					<view class="uni-input">{{showBirthday}}</view>
				</picker>
			</view>
			<view class="item">
				<text class="key">性别</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<picker :value="sexIndex" :range="sexArrayName" @change="sexChange">{{sexArrayName[sexIndex]==undefined?"请选择":sexArrayName[sexIndex]}}
				</picker>
			</view>
			<view class="item" @tap="editIdCard">
				<text class="key">身份证号</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<text class="value">{{idCard}}</text>
			</view>
			<uni-popup ref="popupIdCard" type="dialog">
				<uni-popup-dialog mode="input" title="身份证号" :value="idCard" placeholder="请填写真实身份证号" @confirm="finishIdCard">
				</uni-popup-dialog>
			</uni-popup>
			<view class="item">
				<text class="key">民族</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<picker :value="ethnicIndex" :range="ethnicArrayName" @change="ethnicChange">{{ethnicArrayName[ethnicIndex]==undefined?"请选择":ethnicArrayName[ethnicIndex]}}
				</picker>
			</view>
			<view class="item">
				<text class="key">学历</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<picker :value="degreeIndex" :range="degreeArrayName" @change="degreeChange">{{degreeArrayName[degreeIndex]==undefined?"请选择":degreeArrayName[degreeIndex]}}
				</picker>
			</view>
			<!-- todo -->
			<view class="item" @tap="editGraduate">
				<text class="key">毕业院校</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<text class="value">{{graduate}}</text>
			</view>
			<uni-popup ref="popupGraduate" type="dialog">
				<uni-popup-dialog mode="input" title="毕业院校" :value="graduate" placeholder="请填写真实毕业院校" @confirm="finishGraduate">
				</uni-popup-dialog>
			</uni-popup>
			<view class="item">
				<text class="key">政治面貌</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<picker :value="identityIndex" :range="identityArrayName" @change="identityChange">{{identityArrayName[identityIndex]==undefined?"请选择":identityArrayName[identityIndex]}}
				</picker>
			</view>
			<view class="item">
				<text class="key">户籍地</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<picker :value="domicileIndex" :range="domicileArrayName" @change="domicileChange">{{domicileArrayName[domicileIndex]==undefined?"请选择":domicileArrayName[domicileIndex]}}
				</picker>
			</view>
			<view class="item" @tap="editAddress">
				<text class="key">具体地址</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<text class="value">{{address}}</text>
			</view>
			<uni-popup ref="popupAddress" type="dialog">
				<uni-popup-dialog mode="input" title="具体地址" :value="address" placeholder="请填写家庭住址" @confirm="finishAddress">
				</uni-popup-dialog>
			</uni-popup>
			<view class="item">
				<text class="key">所在组织</text>
				<text class="value">{{organization}}</text>
			</view>
			<view class="item">
				<text class="key">任职岗位</text>
				<text class="value">{{post}}</text>
			</view>
			<view class="item">
				<text class="key">联系号码</text>
				<text class="value">{{account}}</text>
			</view>
			<view class="item">
				<text class="key">邮箱</text>
				<text class="value">{{email}}</text>
			</view>
			<uni-popup ref="popupEmail" type="dialog">
				<uni-popup-dialog mode="input" title="常用邮箱" :value="email" placeholder="请填写真实邮箱" @confirm="finishEmali">
				</uni-popup-dialog>
			</uni-popup>
			<view class="item" @tap="editVx">
				<text class="key">微信号</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<text class="value">{{vx}}</text>
			</view>
			<uni-popup ref="popupVx" type="dialog">
				<uni-popup-dialog mode="input" title="微信号" :value="vx" placeholder="请填写真实微信号" @confirm="finishVx">
				</uni-popup-dialog>
			</uni-popup>
			<view class="item" @tap="editContact">
				<text class="key">其他联系方式</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<text class="value">{{contact}}</text>
			</view>
			<uni-popup ref="popupContact" type="dialog">
				<uni-popup-dialog mode="input" title="联系方式" :value="contact" placeholder="请填写相关联系方式比如:QQ:xxx" @confirm="finishContact">
				</uni-popup-dialog>
			</uni-popup>
			<view class="item">
				<text class="key">登记日期</text>
				<text class="value">{{createTime}}</text>
			</view>
			<view class="item" @tap="editDesc">
				<text class="key">自我介绍</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<text class="value">{{description}}</text>
			</view>
			<uni-popup ref="popupDesc" type="dialog">
				<uni-popup-dialog mode="input" title="自我介绍" :value="description" placeholder="请简单介绍一下自己吧,不超过30字!" @confirm="finishDesc">
				</uni-popup-dialog>
			</uni-popup>
			<view class="item" @tap="editMotto">
				<text class="key">座右铭</text>
				<uni-icons type="compose" size="20"></uni-icons>
				<text class="value">{{motto}}</text>
			</view>			
			<uni-popup ref="popupMotto" type="dialog">
				<uni-popup-dialog mode="input" title="座右铭" :value="motto" placeholder="请简要概述自己的座右铭,不超过20字!" @confirm="finishMotto">
				</uni-popup-dialog>
			</uni-popup>
		</view>
		<uni-section title="请选择证件照" type="line" v-if="comit && isAvater">
			<view class="example-body" >
				<uni-file-picker
					file-mediatype="image"
					disable-preview
					:del-icon="false"
					mode="grid"
					ref="file"
					file-extname="png,jpg"
					:limit="1"
					:auto-upload="false"
					:source-type=source
					@select="getPhotoPath"
				></uni-file-picker>
			</view>
		</uni-section>
		<uni-steps :options="stepList" :active-icon="icon" :active-color="color" :active="active" direction="column" v-if="step" />
		<button class="save-btn" @tap="save" v-if="comit">提 交</button>
		<button class="save-btn" @tap="undo" v-if="revoke">撤 销</button>
		<button class="save-btn" @tap="remit" v-if="over">重新登记</button>
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue';
	import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue';
	import uniFilePicker from '@/components/uni-file-picker/uni-file-picker.vue';
	import uniSection from '@/components/uni-section/uni-section.vue';
	import uniSteps from '@/components/uni-steps/uni-steps.vue';
	export default {
		components: {
			uniPopup,
			uniPopupMessage,
			uniPopupDialog,
			uniFilePicker,
			uniSection,
			uniSteps
		},
		data() {
			return {
				//是否登记过
				isRegistration:'',
				//审批人选择
				approvalArrayName:[],
				approvalArrayId:[],
				approvaUserlId:-1,
				approvalIndex:0,
				// 姓名
				name:'',
				// 生日
				birthday:'',
				showBirthday:'',
				// 性别
				sexArrayName:[],
				sexArrayId:[],
				sexId:-1,
				sexIndex:0,
				// 身份证号
				idCard:'',
				//民族
				ethnicArrayName:[],
				ethnicArrayId:[],
				ethnicId:-1,
				ethnicIndex:0,
				// 学历
				degreeArrayName:[],
				degreeArrayId:[],
				degreeId:-1,
				degreeIndex:0,
				// 毕业院校
				graduate:'',
				// 身份背景
				identityArrayName:[],
				identityArrayId:[],
				identityId:-1,
				identityIndex:0,
				// 户籍地
				domicileArrayName:[],
				domicileArrayId:[],
				domicileId:-1,
				domicileIndex:0,
				// 具体住址
				address:'',
				// 所在组织
				organization:'',
				organizationId:0,
				// 岗位
				post:'',
				// 账号(手机号)
				account:'',
				// 邮箱
				email:'',
				// 微信号
				vx:'',
				// 联系方式
				contact:'',
				// 登记日期
				createTime:'',
				// 自我介绍
				description:'',
				// 座右铭
				motto:'',
				// 当前日期
				nowDate:'',
				// 当前时间
				nowTime:'',
				// 附件
				tempFilePaths:[],
				// 从本地相册中选择
				source:['album'],
				// 是否具有证件照
				isAvater:true,
				// 提交状态
				comit:true,
				// 审核状态
				// 撤销状态
				revoke:false,
				//当前审批id
				approvalId:0,
				// 审核步骤
				step:false,
				// 激活步骤
				active: 0,
				// 步骤线
				stepList: [],
				// 步骤线颜色
				color:"#007AFF",
				// 步骤前icon
				icon:"smallcircle-filled",
				// 完成状态
				over:false
			}
		},
		onLoad:function(){
			let that = this;
			let now = new Date();
			let year = now.getFullYear();
			let month = now.getMonth() + 1;
			month = month < 10 ? '0' + month : month;
			let date = now.getDate();
			date = date < 10 ? '0' + date : date;
			let yyyymmdd = year + '/' + month + '/' + date
			let yyyy_mm_dd = year + '-' + month + '-' + date
			that.nowDate = yyyymmdd;
			that.showBirthday = that.birthday;
			that.nowTime = yyyy_mm_dd;
			// 加载性别数据
			that.loadSexData(that);
			// 加载民族数据
			that.loadEthnicData(that);
			// 加载学历数据
			that.loadDegreeData(that);
			// 加载身份数据
			that.loadIdentityData(that);
			// 加载户籍地数据
			that.loadDomicileData(that);
			// 加载登记时间
			that.loadCreateTime(that);
		},
		onShow: function() {
			let that = this;
			//加载初始化用户相关信息
			that.loadInitUser(that);
			// 判断当前页面是否为审批状态
			that.curApproval(that);
		},
		methods: {
			//判断当前页面是否为审批状态
			curApproval:function(ref){
				ref.ajax(ref.url.curApproval,'POST',{
					approvalType:'entry'
				},function(resp){
					let data = resp.data;
					//如果是
					if(data.curApproval.length>0){
						//当前审批的数据
						let cur = data.curApproval[0];
						//提交内容不可见，提交按钮不可见
						ref.comit = false;
						//步骤条可见
						ref.step = true;
						ref.active = cur.approvalStatus;
						//当前审核id
						ref.approvalId = cur.id;
						//待审核时显示
						if(cur.approvalStatus==1){
							ref.stepList = [
								{title: '已提交',desc: '提交日期:'+ref.formatDataTime(cur.applyTime)}, 
								{title: '待审核',desc: '审核中，请耐心等待……'},
								]
								ref.revoke = true
						}
						//已审核（通过时显示）
						if(cur.approvalStatus==2){
							ref.color="#55aa00"
							ref.revoke = false
							ref.over = true
							ref.stepList = [
								{title: '已提交',desc: '提交日期:'+ref.formatDataTime(cur.applyTime)}, 
								{title: '待审核',desc: '审核日期:'+ref.formatDataTime(cur.applyTime)},
								{title: '通过',desc: '本次提交已通过'}
								]
							if(!ref.isRegistration){
								ref.ajax(ref.url.updateRegistration,'POST',{
									status:true
								},function(resp){
									let data = resp.data;
									if(data.code==20000){
										ref.isRegistration=true;
									}
								})
							}
						}
						//已审核（未通过时显示）
						if(cur.approvalStatus==3){
							ref.revoke = false
							ref.over = true
							ref.stepList = [
								{title: '已提交',desc: '提交日期:'+ref.formatDataTime(cur.applyTime)}, 
								{title: '待审核',desc: '审核日期:'+ref.formatDataTime(cur.applyTime)},
								{title: '未通过',desc: '未通过理由:'+cur.approvalReason}
								]
							ref.color="#ff0000"
						}
					}
				});
			},
			//加载初始化用户信息
			loadInitUser:function(ref){
					ref.ajax(ref.url.getuserinfo, "POST", null, function(resp) {
					let data = resp.data;
					let user = data.userinfo.user;
					let roles = data.userinfo.roles;
					
					let message = "未填写";
					ref.isRegistration = user.isRegistration;
					// 姓名
					if(user.name==null){
						if(uni.getStorageSync("user-name")==''){
							ref.name = "新员工"
						}else{
							ref.name = uni.getStorageSync("user-name")
						}
					}else{
						ref.name = user.name;
					}
					// 生日
					if(user.birthday==null){
						if(uni.getStorageSync("user-showBirthday")==''){ 
							ref.showBirthday = message
						}else{
							ref.birthday =uni.getStorageSync("user-birthday")
							ref.showBirthday = uni.getStorageSync("user-showBirthday")
						}
					}else{
						ref.birthday = user.birthday
						ref.showBirthday = ref.formatDataTime(user.birthday)
					}
					// 性别
					if(user.sex!=null){
						ref.sexId = user.sex.id;
						ref.sexIndex = ref.sexArrayId.indexOf(ref.sexId)
					}else{
						if(typeof(uni.getStorageSync("user-sexId"))=='number'){
							ref.sexId = uni.getStorageSync("user-sexId");
							ref.sexIndex = ref.sexArrayId.indexOf(ref.sexId);
						}
					}
					// 身份证号
					if(user.idCard==null){
						if(uni.getStorageSync("user-idCard")==''){
							ref.idCard = message
						}else{
							ref.idCard = uni.getStorageSync("user-idCard")
						}
					}else{
						ref.idCard = user.idCard
					}
					// 民族
					if(user.ethnic!=null){
						ref.ethnicId = user.ethnic.id;
						ref.ethnicIndex = ref.ethnicArrayId.indexOf(ref.ethnicId)
					}else{
						if(typeof(uni.getStorageSync("user-ethnicId"))=='number'){
							ref.ethnicId = uni.getStorageSync("user-ethnicId");
							ref.ethnicIndex = ref.ethnicArrayId.indexOf(ref.ethnicId);
						}
					}
					// 学历
					if(user.degree!=null){
						ref.degreeId = user.degree.id;
						ref.degreeIndex = ref.degreeArrayId.indexOf(ref.degreeId)
					}else{
						if(typeof(uni.getStorageSync("user-degreeId"))=='number'){
							ref.degreeId = uni.getStorageSync("user-degreeId");
							ref.degreeIndex = ref.degreeArrayId.indexOf(ref.degreeId)
						}
					}
					// 毕业院校
					if(user.graduate == null){
						if(uni.getStorageSync("user-graduate")==''){
							ref.graduate = message;
						}else{
							ref.graduate = uni.getStorageSync("user-graduate")
						}
					}else{
						ref.graduate = user.graduate;
					}
					// 身份背景
					if(user.identity!=null){
						ref.identityId = user.identity.id;
						ref.identityIndex = ref.identityArrayId.indexOf(ref.identityId)
					}else{
						if(typeof(uni.getStorageSync("user-identityId"))=='number'){
							ref.identityId = uni.getStorageSync("user-identityId");
							ref.identityIndex = ref.identityArrayId.indexOf(ref.identityId);
						}
					}
					//户籍地
					if(user.domicile!=null){
						ref.domicileId = user.domicile.id;
						ref.domicileIndex = ref.domicileArrayId.indexOf(ref.domicileId)
					}else{
						if(typeof(uni.getStorageSync("user-domicileId"))=='number'){
							ref.domicileId = uni.getStorageSync("user-domicileId")
							ref.domicileIndex = ref.domicileArrayId.indexOf(ref.domicileId)
						}
					}
					// 具体地址
					if(user.address==null){
						if(uni.getStorageSync("user-address")==''){
							ref.address = message
						}else{
							ref.address = uni.getStorageSync("user-address")
						}
					}else{
						ref.address = user.address
					}
					// 组织
					if(user.organization==null){
						ref.organization = message
					}else{
						ref.organization = user.organization.name
						ref.organizationId = user.organization.id;
						//加载审批人数据
						ref.loadArrovalData(ref);
					}
					// 岗位
					if(user.job==null){
						ref.post = message
					}else{
						ref.post = user.job.name
					}
					// 账号
					if(user.account==null){
						ref.account = message
					}else{
						ref.account = user.account
					}
					// 电子邮件
					if(user.email==null){
						ref.email = message
					}else{
						ref.email = user.email
					}
					// 微信
					if(user.vx==null){
						if(uni.getStorageSync("user-vx")==''){
							ref.vx = message
						}else{
							ref.vx = uni.getStorageSync("user-vx")
						}
					}else{
						ref.vx = user.vx
					}
					// 联系方式
					if(user.contact==null){
						if(uni.getStorageSync("user-contact")==''){
							ref.contact = message
						}else{
							ref.contact = uni.getStorageSync("user-contact")
						}
					}else{
						ref.contact = user.contact
					}
					// 登记时间
					if(user.createTime!=null){
						ref.createTime = ref.formatTime(user.createTime)
					}
					// 自我介绍
					if(user.description==null){
						if(uni.getStorageSync("user-description")==''){
							ref.description = message
						}else{
							ref.description = uni.getStorageSync("user-description")
						}
					}else{
						ref.description = user.description
					}
					// 座右铭
					if(user.motto==null){
						if(uni.getStorageSync("user-motto")==''){
							ref.motto = message
						}else{
							ref.motto = uni.getStorageSync("user-motto")
						}
					}else{
						ref.motto = user.motto
					}
					//是否具有证件照
					if(user.avater!=null && user.avater.length>0){
						ref.isAvater = false;
					}
				});
			},
			//加载审批人数据
			loadArrovalData(ref){
				console.log(ref.organizationId)
				ref.ajax(ref.url.getAdmins,'POST',{
					id:ref.organizationId
				},function(resp){
					let data = resp.data.data;
					console.log(data)
					let arrName = [];
					let arrId=[];
					for(let one of data){
						ref.approvalArrayId.push(one.id);
						ref.approvalArrayName.push(one.name);
					}
					ref.approvaUserlId = ref.approvalArrayId[0];
					console.log(ref.approvaUserlId)
					ref.approvalIndex = ref.approvalArrayId.indexOf(ref.approvaUserlId)
				});
			},
			//选择审批人
			approvalChange: function(e) {
				let that = this;
				that.approvalIndex = e.detail.value;
				uni.setStorageSync("user-approvalUserId",that.approvalArrayId[that.approvalIndex])
				that.approvaUserlId = uni.getStorageSync("user-approvalUserId");
			},
			// 编辑姓名
			editName: function() {
				this.$refs.popupName.open();
			},
			// 完成编辑姓名
			finishName: function(done, value) {
				let that = this;
				if (!that.checkValidName(value, '姓名')) {
					uni.setStorageSync("user-name",value);
					that.name = uni.getStorageSync("user-name");
					done();
				}
			},
			// 生日日期选择
			birthdayChange: function(e) {
				let now = new Date();
				// 获取小时、分钟和秒数，并进行格式化
				let hours = now.getHours();
				hours = hours < 10 ? '0' + hours : hours; // 对于24小时制不需要额外处理
				let minutes = now.getMinutes();
				minutes = minutes < 10 ? '0' + minutes : minutes;
				let seconds = now.getSeconds();
				seconds = seconds < 10 ? '0' + seconds : seconds;
				//获取选择到的内容
				let value= e.detail.value;
				//开始日期
				let dates = value+' '+hours+':'+minutes+':'+ seconds;
				let curDates = new Date(value.replace(/-/g, '/')+' '+hours+':'+minutes+':'+ seconds).getTime();
				//结束日期
				let nowDates = new Date(this.nowDate+' '+hours+':'+minutes+':'+ seconds).getTime();
				if (nowDates<=curDates) {
					uni.showToast({
						icon: "error",
						title: "时间选择不正确"
					});
				}else{
					uni.setStorageSync("user-birthday",dates)
					this.birthday = uni.getStorageSync("user-birthday");
					console.log(this.birthday)
					uni.setStorageSync("user-showBirthday",value)
					this.showBirthday = uni.getStorageSync("user-showBirthday");
				}
			},
			// 加载性别数据
			loadSexData(ref){
				ref.ajax(ref.url.getDict,'POST',{
					type:"sex"
				},function(resp){
					let data = resp.data.data;
					let arrName = [];
					let arrId=[];
					for(let one of data){
						arrId.push(one.id);
						arrName.push(one.name);
					}
					ref.sexArrayName = arrName;
					ref.sexArrayId = arrId;
					ref.sexId = ref.sexArrayId[0];
					ref.sexIndex = ref.sexArrayId.indexOf(ref.sexId)
				});
			},
			// 性别选择
			sexChange: function(e) {
				let that = this;
				that.sexIndex = e.detail.value;
				uni.setStorageSync("user-sexId",that.sexArrayId[that.sexIndex])
				that.sexId = uni.getStorageSync("user-sexId");
			},
			// 编辑身份证号
			editIdCard:function(){
				this.$refs.popupIdCard.open();
			},
			// 完成编辑身份证号
			finishIdCard: function(done, value) {
				let that = this;
				if (!that.checkValidIdCard(value, '身份证号')) {
					uni.setStorageSync("user-idCard",value)
					that.idCard = uni.getStorageSync("user-idCard");
					done();
				}
			},
			// 加载民族数据
			loadEthnicData(ref){
				ref.ajax(ref.url.getDict,'POST',{
					type:"ethnic"
				},function(resp){
					let data = resp.data.data;
					let arrName = [];
					let arrId=[];
					for(let one of data){
						ref.ethnicArrayId.push(one.id);
						ref.ethnicArrayName.push(one.name);
					}
					ref.ethnicId = ref.ethnicArrayId[0];
					ref.ethnicIndex = ref.ethnicArrayId.indexOf(ref.ethnicId)
				});
			},
			// 民族选择
			ethnicChange:function(e){
				let that = this;
				that.ethnicIndex = e.detail.value;
				uni.setStorageSync("user-ethnicId",that.ethnicArrayId[that.ethnicIndex])
				that.ethnicId = uni.getStorageSync("user-ethnicId");
			},
			// 加载学历数据
			loadDegreeData(ref){
				ref.ajax(ref.url.getDict,'POST',{
					type:"degree"
				},function(resp){
					let data = resp.data.data;
					let arrName = [];
					let arrId=[];
					for(let one of data){
						arrId.push(one.id);
						arrName.push(one.name);
					}
					ref.degreeArrayName = arrName;
					ref.degreeArrayId = arrId;
					ref.degreeId = ref.degreeArrayId[0];
					ref.degreeIndex = ref.degreeArrayId.indexOf(ref.degreeId)
				});
			},
			// 学历选择
			degreeChange:function(e){
				let that = this;
				that.degreeIndex = e.detail.value;
				uni.setStorageSync("user-degreeId",that.degreeArrayId[that.degreeIndex])
				that.degreeId = uni.getStorageSync("user-degreeId");
			},
			// 编写毕业院校
			editGraduate(){
				this.$refs.popupGraduate.open();
			},
			// 完成毕业院校
			finishGraduate: function(done, value) {
				let that = this;
				uni.setStorageSync("user-graduate",value)
				that.graduate = uni.getStorageSync("user-graduate");
				done();
			},
			// 加载身份背景
			loadIdentityData(ref){
				ref.ajax(ref.url.getDict,'POST',{
					type:"identity"
				},function(resp){
					let data = resp.data.data;
					let arrName = [];
					let arrId=[];
					for(let one of data){
						arrId.push(one.id);
						arrName.push(one.name);
					}
					ref.identityArrayName = arrName;
					ref.identityArrayId = arrId;
					ref.identityId = ref.identityArrayId[0];
					ref.identityIndex = ref.identityArrayId.indexOf(ref.identityId)
				});
			},
			// 选择身份
			identityChange:function(e){
				let that = this;
				that.identityIndex= e.detail.value;
				uni.setStorageSync("user-identityId",that.identityArrayId[that.identityIndex])
				that.identityId = uni.getStorageSync("user-identityId");
			},
			// 加载户籍地数据
			loadDomicileData(ref){
				ref.ajax(ref.url.getDict,'POST',{
					type:"domicile"
				},function(resp){
					let data = resp.data.data;
					let arrName = [];
					let arrId=[];
					for(let one of data){
						arrId.push(one.id);
						arrName.push(one.name);
					}
					ref.domicileArrayName = arrName;
					ref.domicileArrayId = arrId;
					ref.domicileId = ref.domicileArrayId[0];
					ref.domicileIndex = ref.domicileArrayId.indexOf(ref.domicileId)
				});
			},
			// 户籍地选择
			domicileChange:function(e){
				let that = this;
				that.domicileIndex= e.detail.value;
				uni.setStorageSync("user-domicileId",that.domicileArrayId[that.domicileIndex])
				that.domicileId = uni.getStorageSync("user-domicileId");
			},
			// 编写具体地址
			editAddress(){
				this.$refs.popupAddress.open();
			},
			// 完成具体地址编写
			finishAddress: function(done, value) {
				let that = this;
				uni.setStorageSync("user-address",value)
				that.address = uni.getStorageSync("user-address");
				done();
			},
			// 编辑VX
			editVx: function() {
				this.$refs.popupVx.open();
			},
			// 完成VX信息编辑
			finishVx: function(done, value) {
				let that = this;
				uni.setStorageSync("user-vx",value)
				that.vx = uni.getStorageSync("user-vx");
				done();
			},
			// 编辑联系方式
			editContact: function() {
				this.$refs.popupContact.open();
			},
			// 完成联系方式编辑
			finishContact: function(done, value) {
				let that = this;
				uni.setStorageSync("user-contact",value)
				that.contact = uni.getStorageSync("user-contact");
				done();
			},
			// 加载登记日期
			loadCreateTime(ref){
				let now = new Date();
				// 获取小时、分钟和秒数，并进行格式化
				let hours = now.getHours();
				hours = hours < 10 ? '0' + hours : hours; // 对于24小时制不需要额外处理
				let minutes = now.getMinutes();
				minutes = minutes < 10 ? '0' + minutes : minutes;
				let seconds = now.getSeconds();
				seconds = seconds < 10 ? '0' + seconds : seconds;
				ref.createTime = ref.nowTime+' '+hours+':'+minutes+':'+ seconds;
			},
			// 编辑自我描述
			editDesc:function(){
				this.$refs.popupDesc.open();
			},
			// 完成自我描述
			finishDesc:function(done,value){
				let that = this;
				if(value.length>=30){
					uni.showToast({
						title:"字数太多",
						icon:'error'
					});
					return
				}else{
					uni.setStorageSync("user-description",value)
					that.description = uni.getStorageSync("user-description");
				}
				done();
			},
			// 编辑座右铭
			editMotto:function(){
				this.$refs.popupMotto.open();
			},
			// 完成座右铭编辑
			finishMotto:function(done,value){
				let that = this;
				if(value.length>=20){
					uni.showToast({
						title:"字数太多",
						icon:'error'
					});
					return;
				}else{
					uni.setStorageSync("user-motto",value)
					that.motto = uni.getStorageSync("user-motto");
				}
				done();
			},
			// 获取照片路径
			getPhotoPath(e){
				let that = this;
				that.tempFilePaths = e.tempFilePaths;
			},
			// 提交审批
			save: function() {
				let that = this;
				if(
					//选择的审批人的id是否选择
					that.approvaUserlId<=0 ||
					//姓名是否为空
					that.name.length<=0||
					//生日是否为空
					that.birthday.length<=0||
					//性别的id是否选择
					that.sexId<0||
					//身份证号码是否为空
					that.idCard.length<0||
					//是否选择了民族id
					that.ethnicId<0||
					//是否选择了学历id
					that.degreeId<0||
					//毕业院校是否填写
					that.graduate.length<0||
					//是否选择了身份id
					that.identityId<0||
					//是否选择了户籍地id
					that.domicileId<0||
					//是否填写了具体的家庭住址
					that.address.length<0||
					//是否填写了VX信息
					that.vx.length<=0||
					//是否填写了其他联系方式
					that.contact.length<=0||
					//是否填写了自我介绍
					that.description.length<=0||
					//是否填写了座右铭
					that.motto.length<=0||
					//在没有提交过头像的情况下是否上传了头像路径
					(that.tempFilePaths.length<=0 && that.isAvater == true)
				){
					uni.showToast({
						icon: 'error',
						title: '请填写完整相关内容',
					});
				}else{
					uni.showModal({
						title: '提示',
						content: '是否提交员工登记信息申请',
						success: function(e) {
							if (e.confirm) {
								//是否已经提交过了照片
								if(that.isAvater){
									//未提交过时上传图片到后端
									uni.uploadFile({
										url:that.url.updateAvater,
										filePath:that.tempFilePaths[0],
										name:"files",
										header:{
											token:uni.getStorageSync("token")
										},
										formData:{
											type:'avater'
										},
										success:(uploadFileRes) => {
											let data = JSON.parse(uploadFileRes.data);
											that.isAvater= false
										}
									});
								}
								//修改用户信息表单
								let form={
									name:that.name,
									birthday:that.birthday,
									sexId:that.sexId,
									idCard:that.idCard,
									ethnicId:that.ethnicId,
									degreeId:that.degreeId,
									graduate:that.graduate,
									identityId:that.identityId,
									domicileId:that.domicileId,
									address:that.address,
									vx:that.vx,
									contact:that.contact,
									description:that.description,
									motto:that.motto
								}
								that.ajax(that.url.updateUserInfo,'PUT',form,function(resp){
									let data = resp.data;
									if(data.code===20000){
										uni.showToast({
											icon: 'success',
											title: '登记成功',
										});
										let curApprovalUserId='';
										if(typeof(uni.getStorageSync('user-approvalUserId'))!='number'){
											curApprovalUserId = that.approvaUserlId
										}else{
											curApprovalUserId = uni.getStorageSync('user-approvalUserId')
										}
										that.ajax(that.url.applyApproval,'POST',{
											approvalId:curApprovalUserId,
											approvalType:"entry"
										},function(resp){
											let data = resp.data;
											//激发为待审核状态（第一次提交时或重新提交时）
											if(data.code===20000){
												//提交内容不可见，提交按钮不可见
												that.comit = false
												//撤销按钮可用
												that.revoke = true
												//步骤条可用
												that.step = true
												//获取当前的审批id
												that.approvalId = data.approvalInfo.id;
												//待审核状态
												that.active = data.approvalInfo.approvalStatus;
												that.stepList = [
													{title: '已提交',desc: '提交日期:'+that.formatDataTime(data.approvalInfo.applyTime)}, 
													{title: '待审核',desc: '审核中，请耐心等待……'},
													]
											}
										});
									}
								});
							}
						}
					});
				}
			},
			//撤销审批
			undo:function(){
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否确认撤销登记信息',
					success: function(e) {
						if (e.confirm) {
							let form={
								id:that.approvalId,
								cutStatus:1
							}
							that.ajax(that.url.setCut,'POST',form,function(resp){
								let data = resp.data;
								if(data.code===20000){
									that.ajax(that.url.updateRegistration,'POST',{
										status:false
									},function(resp){
										let data = resp.data;
										if(data.code==20000){
											uni.showToast({
												icon: 'success',
												title: data.msg,
											});
											//撤销按钮不可见
											that.revoke = false;
											//步骤条不可见
											that.step = false;
											//提交内容和提交按钮可见
											that.comit = true;
											//恢复步骤条颜色
											that.color = "#007AFF";
										}
									});
								}
							})
						}
					}
				});
			},
			//重新提交
			remit:function(){
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否确认重新登记信息',
					success: function(e) {
						if (e.confirm) {
							let form={
								id:that.approvalId,
								cutStatus:1
							}
							that.ajax(that.url.setCut,'POST',form,function(resp){
								let data = resp.data;
								if(data.code===20000){
									that.ajax(that.url.updateRegistration,'POST',{
										status:false
									},function(resp){
										let data = resp.data;
										if(data.code==20000){
											uni.showToast({
												icon: 'success',
												title: '重新登记',
											});
											//重新提交按钮不可见
											that.over = false;
											//步骤条不可见
											that.step = false;
											//提交内容和提交按钮可见
											that.comit = true;
											//恢复颜色
											that.color = "#007AFF";
										}
									});
								}
							})
						}
					}
				});
			}
		}
	}
</script>

<style lang="less">
@import url('registration.less');
</style>